package listbyorder.access101_200.test198;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/15 14:18
 */
public class Solution1 {

    public int rob(int[] nums) {
        if (nums.length == 0) return 0;
        int[] dp = new int[nums.length + 1];
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                dp[i + 1] = nums[i];
            } else {
                dp[i + 1] = Math.max(dp[i], dp[i - 1] + nums[i]);
            }
        }
        return dp[nums.length];
    }
}
